// 判断用户有没有登录，没有登录跳转到登录页面
if (!localStorage.getItem('token')) {
    //   /login是根目录的login
    location.href = '/login.html'
}
// 加载用户的基本信息
async function reqGetUserFn() {
    const res = await reqGetUserInfo()
    console.log(res);
    let {
        data: {
            nickname,
            user_pic,
            username
        }
    } = res.data;
    // console.log(nickname,user_pic,username);
    if (user_pic !== null) {
        $('.userinfo img').css('display', 'inline-block').attr('src', user_pic);
    } else {
        $('.userinfo .avatar').css('display', 'inline-block').text(username[0]);
    }
    // if (username === '') {
    //     $('.userinfo .username').text(nickname);
    // }else{
    //     $('.userinfo .username').text(username);
    // }
    if (nickname === '') {
        nickname = username
    }
    $('.userinfo .username').text(nickname);

}
reqGetUserFn()


// 退出
$('#logout').on('click', function () {
    layer.confirm('你确定要退出吗?', {
        icon: 3,
        title: '提示'
    }, function () {
        localStorage.removeItem('token');
        location.href = '/login.html';
    });
})